package com.fyzk.activity.zhifu;

import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.fyzk.betcode.BetLotteryInfo;
import com.fyzk.constants.ConstantsDJ;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

public class NumLotteryZhiFuAdapter extends BaseAdapter {

	private Context context;
	private List<BetLotteryInfo> infos = new ArrayList<BetLotteryInfo>();
	public NumLotteryZhiFuOnClick listener;
	private int oneAmount = 2;

	public NumLotteryZhiFuAdapter(Context context, List<BetLotteryInfo> infos,
			int oneAmount) {
		this.context = context;
		this.infos = infos;
		this.oneAmount = oneAmount;
	}

	@Override
	public void notifyDataSetChanged() {
		// TODO Auto-generated method stub
		super.notifyDataSetChanged();
	}
	

	public void setOneAmount(int oneAmount){
		this.oneAmount = oneAmount;
	}
	

	@Override
	public int getCount() {
		return infos.size() + 1;
	}

	@Override
	public Object getItem(int arg0) {
		return infos.get(arg0);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {

		View view = LayoutInflater.from(context).inflate(
				R.layout.ssq_zhifu_listview, null);

		LinearLayout bg_center = (LinearLayout) view
				.findViewById(R.id.ssq_zhifu_list_ll);

		ImageView delete = (ImageView) view
				.findViewById(R.id.ssq_zhifu_list_delete_iv);

		TextView tv_betNum = (TextView) view
				.findViewById(R.id.ssq_zhifu_list_hong);

		TextView fangshi = (TextView) view
				.findViewById(R.id.ssq_zhifu_list_fangshi);
		TextView zhu = (TextView) view.findViewById(R.id.ssq_zhifu_list_zhu);
		TextView bei = (TextView) view.findViewById(R.id.ssq_zhifu_list_bei);
		TextView qi = (TextView) view.findViewById(R.id.ssq_zhifu_list_qi);
		TextView money = (TextView) view
				.findViewById(R.id.ssq_zhifu_list_money);
		if (position == infos.size()) {

			bg_center.setVisibility(View.GONE);
		} else {
			BetLotteryInfo info = infos.get(position);
			fangshi.setText("[" + ConstantsDJ.wcode(info.wcodeID) + "]");
			tv_betNum.setText(Html.fromHtml(info.showZhuMa));

			zhu.setText(info.zhushu + "注,");
			money.setText("共 " + info.zhushu * oneAmount + " 米");

			bg_center.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (listener != null) {
						listener.onClickChange(position);
					}
				}
			});

			delete.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					if (listener != null) {
						listener.onClickDelete(position);
					}
				}
			});
		}

		return view;
	}

	public interface NumLotteryZhiFuOnClick {
		 void onClickDelete(int position);
		 void onClickChange(int position);
	}

	public void setListener(NumLotteryZhiFuOnClick listener) {
		this.listener = listener;
	}

}
